Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add 'IntoSeries' #991

Merged
merged 24 commits into from
Oct 17, 2024
Merged

Conversation

luke396
Copy link
Member

@luke396 luke396 commented Sep 18, 2024

What type of PR is this? (check all applicable)

  • πŸ’Ύ Refactor
  • ✨ Feature
  • πŸ› Bug Fix
  • πŸ”§ Optimization
  • πŸ“ Documentation
  • βœ… Test
  • 🐳 Other

Related issues

Checklist

  • Code follows style guide (ruff)
  • Tests added
  • Documented the changes

If you have comments or can explain your changes, please do so below.

I think I should keep learning from #365 to improve the current PR.

@github-actions github-actions bot added the enhancement New feature or request label Sep 18, 2024
@luke396 luke396 marked this pull request as ready for review October 6, 2024 04:43
Copy link
Member

@MarcoGorelli MarcoGorelli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks @luke396 !

sorry this took me a while to get to, I had a company retreat + holiday recently so had relatively little time

looks good, just got a little question

@luke396
Copy link
Member Author

luke396 commented Oct 16, 2024

looks good, just got a little question

Should we miss some questions here?

Comment on lines 54 to 56
IntoSeries: TypeAlias = Union[
"Series", "DataFrame[Any]", "LazyFrame[Any]", "NativeSeries"
]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry, the question didn't go for some reason

I wanted to ask, why include "DataFrame[Any]", "LazyFrame[Any]" here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't recall any particular reason; I just defined it to pass all checks and seem to have forgotten to restrict it again.

Let's try how about remove them.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems fine!

@@ -738,7 +739,7 @@ def from_native(

@overload
def from_native(
native_dataframe: Any,
native_dataframe: IntoSeriesT | Any, # remain `Any` for downstream compatibility
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for https://github.com/vega/altair/blob/796649efd751a7b928ac4f81e192d0ae93f4a3d0/altair/utils/schemapi.py#L502C1-L507C25

def _from_array_like(obj: Iterable[Any], /) -> list[Any]:
    try:
        ser = nw.from_native(obj, strict=True, series_only=True)
        return ser.to_list()
    except TypeError:
        return list(obj)

Comment on lines 32 to 34
class NativeSeries(Protocol):
@property
def name(self) -> Any: ...
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure this is true in general unfortunately 😭

In [4]: pa.chunked_array([['a', 'b', 'c']]).name
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In[4], line 1
----> 1 pa.chunked_array([['a', 'b', 'c']]).name

AttributeError: 'pyarrow.lib.ChunkedArray' object has no attribute 'name'

let's just put __len__?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the correction. I didn't consider the situation.

Copy link
Member

@MarcoGorelli MarcoGorelli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks @luke396 !

@MarcoGorelli MarcoGorelli merged commit 9b628ee into narwhals-dev:main Oct 17, 2024
25 checks passed
@luke396 luke396 deleted the add-IntoSeries branch October 17, 2024 10:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add IntoSeries type hint
2 participants